package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.CstReimbursePayment;
import com.ruoyi.system.service.ICstReimbursePaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报销支付Controller
 * 
 * @author zjw
 * @date 2023-01-04
 */
@RestController
@RequestMapping("/cst/payment")
public class CstReimbursePaymentController extends BaseController
{
    @Autowired
    private ICstReimbursePaymentService cstReimbursePaymentService;

    /**
     * 查询报销支付列表
     */
    @PreAuthorize("@ss.hasPermi('cst:payment:list')")
    @GetMapping("/list")
    public TableDataInfo list(CstReimbursePayment cstReimbursePayment)
    {
        startPage();
        List<CstReimbursePayment> list = cstReimbursePaymentService.selectCstReimbursePaymentList(cstReimbursePayment);
        return getDataTable(list);
    }

    /**
     * 导出报销支付列表
     */
    @PreAuthorize("@ss.hasPermi('cst:payment:export')")
    @Log(title = "报销支付", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CstReimbursePayment cstReimbursePayment)
    {
        List<CstReimbursePayment> list = cstReimbursePaymentService.selectCstReimbursePaymentList(cstReimbursePayment);
        ExcelUtil<CstReimbursePayment> util = new ExcelUtil<CstReimbursePayment>(CstReimbursePayment.class);
        util.exportExcel(response, list, "报销支付数据");
    }

    /**
     * 获取报销支付详细信息
     */
    @PreAuthorize("@ss.hasPermi('cst:payment:query')")
    @GetMapping(value = "/{paymentId}")
    public AjaxResult getInfo(@PathVariable("paymentId") Long paymentId)
    {
        return success(cstReimbursePaymentService.selectCstReimbursePaymentByPaymentId(paymentId));
    }

    /**
     * 新增报销支付
     */
    @PreAuthorize("@ss.hasPermi('cst:payment:add')")
    @Log(title = "报销支付", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CstReimbursePayment cstReimbursePayment)
    {
        return toAjax(cstReimbursePaymentService.insertCstReimbursePayment(cstReimbursePayment));
    }

    /**
     * 修改报销支付
     */
    @PreAuthorize("@ss.hasPermi('cst:payment:edit')")
    @Log(title = "报销支付", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CstReimbursePayment cstReimbursePayment)
    {
        return toAjax(cstReimbursePaymentService.updateCstReimbursePayment(cstReimbursePayment));
    }

    /**
     * 删除报销支付
     */
    @PreAuthorize("@ss.hasPermi('cst:payment:remove')")
    @Log(title = "报销支付", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paymentIds}")
    public AjaxResult remove(@PathVariable Long[] paymentIds)
    {
        return toAjax(cstReimbursePaymentService.deleteCstReimbursePaymentByPaymentIds(paymentIds));
    }
}
